package com.xuesi.demoadmin.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.github.pagehelper.PageInfo;
import com.xuesi.demoadmin.annotation.Auth;
import com.xuesi.demoadmin.annotation.Permission;
import com.xuesi.demoadmin.entity.R;
import com.xuesi.demoadmin.service.IPermissionService;
import com.xuesi.demoadmin.utils.PageUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/permissions")
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;

    @SuppressWarnings("unchecked")
    @Auth
    @Permission
    @GetMapping("/list")
    public R<Map<String, Object>> list(@RequestBody com.xuesi.demoadmin.entity.Permission permissionEntity) {
        // 设置请求分页数据
        try {
            PageUtils.startPage();
        } catch (Exception e) {
            return null;
        }

        List<com.xuesi.demoadmin.entity.Permission> list = this.permissionService
                .selectPermissionList(permissionEntity);

        Map<String, Object> result = new HashMap<>();

        result.put("count", new PageInfo(list).getTotal());
        result.put("list", list);

        return new R<Map<String, Object>>(200, "success", result);
    }
}
